package cn.lanqiao.springboot;

import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.text.SimpleDateFormat;
import java.util.Date;

@SpringBootTest
public class RabbitProducer {

    @Autowired
    private AmqpTemplate rabbitTemplate;

    @Test
    public void sendDemoQueue() {
        for (int i = 0; i < 10 ; i++) {
            Date date = new Date();
            String dateString = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.sss").format(date);
            System.out.println("[demoQueue] send msg: " + dateString);
            // 第一个参数为刚刚定义的队列名称
            this.rabbitTemplate.convertAndSend("demoQueue", dateString);
        }

    }
}
